package org.nerve.okhttp3;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * org.nerve.okhttp3
 * Created by zengxm on 2016/7/28.
 */
public class HtmlStringUtil {

	/**
	 * 统计keyword在source中出现的次数
	 * @param source
	 * @param keyword
	 * @return
	 */
	public static final int count(String source,String keyword){
		String regex = "[a-zA-Z]+";
		if (keyword != null && !keyword.equals("")) {
			regex = keyword;
		}
		Pattern expression = Pattern.compile(regex);
		Matcher matcher = expression.matcher(source);
		int n = 0;
		while (matcher.find()) {
			n++;
		}

		return n;
	}

	public static void main(String[] args) {
		System.out.println(count("我们一个人<a class='link'>好的</a>", "link"));
		System.out.println(count("我们一个人<a class='link'>好的</a>", "a"));
		System.out.println(count("我们一个人<a class='link'>好的</a>", "我们"));
		System.out.println(count("我们一个人<a class='link'>好的</a>", "好的"));

		System.out.println(String.format("%s,好的，马上去%s","我知道了","你那里"));
	}
}
